package cn.outsourcing.supermarket.converter;

import cn.outsourcing.supermarket.converter.transform.BooleanToIntegerTransform;
import cn.outsourcing.supermarket.dto.backstage.BackstageCategoryStoreDTO;
import cn.outsourcing.supermarket.po.HiolabsCategory;
import cn.outsourcing.supermarket.vo.CategoryVO;
import cn.outsourcing.supermarket.vo.backstage.BackstageCategoryInfoVO;
import cn.outsourcing.supermarket.vo.backstage.BackstageEzCategoryVO;
import cn.outsourcing.supermarket.vo.hiolabs.HiolabsCategoryVO;
import cn.outsourcing.supermarket.vo.home.HomeChannelVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 分类实体映射器
 *
 * @author gzkemays
 * @since 2021/10/21 23:31
 */
@Mapper(uses = {BooleanToIntegerTransform.class})
public interface HiolabsCategoryConverter {
  HiolabsCategoryConverter INSTANCE = Mappers.getMapper(HiolabsCategoryConverter.class);

  /**
   * 获取部分参数
   *
   * @param category 原分类数据
   * @return VO 实体
   */
  CategoryVO converterCategory(HiolabsCategory category);

  @Mapping(
      target = "level",
      expression =
          "java(cn.outsourcing.supermarket.common.utils.DataUtils.getLevelByLStr(category.getLevel()))")
  BackstageCategoryInfoVO convertToVoInfo(HiolabsCategory category);
  List<BackstageCategoryInfoVO> convertToVoInfoList(List<HiolabsCategory> category);
  HiolabsCategoryVO convertToVo(HiolabsCategory category);

  List<HiolabsCategoryVO> convertToVoList(List<HiolabsCategory> category);

  HomeChannelVO converterToChannel(HiolabsCategory category);

  List<HomeChannelVO> converterToChannelList(List<HiolabsCategory> category);

  @Mappings({
    @Mapping(source = "category.id", target = "value"),
    @Mapping(source = "category.name", target = "label"),
    @Mapping(target = "children", expression = "java(new java.util.ArrayList<>())")
  })
  BackstageEzCategoryVO convertToBackstageEzVo(HiolabsCategory category);

  List<BackstageEzCategoryVO> convertToBackstageEzVoList(List<HiolabsCategory> category);

  /**
   * 将后端分类保存数据转化为 po 对象
   *
   * @param dto 分类保存数据
   * @return po 对象
   */
  HiolabsCategory convertToPoByCategoryStoreDto(BackstageCategoryStoreDTO dto);
}
